<!doctype html>

<html style="height:100%">
    <head>
        <title>test_定时刷新</title>

        <style type="text/css">
            body,input,textarea {font-family:Microsoft YaHei; font-size:100%; border-radius:5px;}
            textarea {width:98%; height:100%; resize:none;}
            table {table-layout:fixed; }
        </style>
        <script src="{{ url_for('static', filename='jquery-3.3.1.js') }}"></script>
        <script type="text/javascript">
            <!-- 校验为空 -->
            function check_null(value, alerttxt)
            {
                if (value != "")
                {
                    return true;
                }
                else
                {
                    alert(alerttxt);
                    return false;
                }
            }

            function submitTimeGet(){
                $('#ret_str').val('')

                var input_line_no = $('#line_no')
                var val_line_no = input_line_no.val()
                if (!check_null(val_line_no, "line_no null!"))
                {
                    input_line_no.focus();
                    return;
                }

                btnSubmit = $('#btnSubmit');
                btnSubmit.attr("disabled", true);

                int_line_no = parseInt(val_line_no)

                var t1 = window.setInterval(function(){
                    $.post('/time_get', {
                        line_no: int_line_no,
                    },
                    function (data, status) {
                        if (status == 'success')
                        {
                            <!-- 'line_str': line_str -->
                            <!-- 'has_next': has_next -->
                            <!-- 'left': left -->
                            ret_json = $.parseJSON(data);

                            if ($('#ret_str').val() == '') {
                                $('#ret_str').val(ret_json.line_str)
                            } else {
                                $('#ret_str').val($('#ret_str').val() + '\n' + ret_json.line_str)
                            }

                            if (ret_json.has_next) {
                                int_line_no++
                                btnSubmit.val('提交(' + ret_json.left + ')');
                            } else {
                                clearInterval(t1)
                                btnSubmit.attr("disabled", false);
                                btnSubmit.val('提交');
                            }
                        }
                        else
                        {
                            $('#ret_str').val($('#ret_str').val() + '\n' + status)
                        }
                    })
                }, 1000);
            }

            <!-- 正则输入框，回车 -->
            function keyDown()
            {
                if(event.keyCode==13)
                {
                    submitTimeGet();
                }
            }
        </script>
    </head>

    <body style="margin:0; width:100%; height:100%">

        <!-- 标题 -->
        <div align=center style="width:100%; height:50px; background:#003399; ">
            <table border=0 style="width:80%; height:100%; ">
                <tr align=left>
                    <th width=30%>
                        <a href="" style="text-decoration:none; color:white; font-size:150%; ">test_定时刷新</a>
                    </th>
                </tr>
            </table>
        </div>

        <!-- 正文 -->
        <div align=center style="width:100%; height:90%; ">
            <table border=0 style="width:80%; height:100%; text-align:center;">
                <tr style="height:50px">
                    <th>
                        输入Line <input type=text id=line_no size=50 onkeydown="keyDown()" value=0>
                        &nbsp;<input type=submit id=btnSubmit value=提交 onclick="submitTimeGet()">
                    </th>
                </tr>

                <tr style="height:20px; background-color:#CC0033; color: white">
                    <th>
                        结果
                    </th>
                </tr>

                <tr>
                    <td>
                        <textarea id=ret_str style="background-color:#EBEBE4"></textarea>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>